.class public final Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;
.super Ljava/lang/Object;
.source "ImageCache.java"

# interfaces
.implements Lcom/burstly/lib/cache/ICache;
.implements Lcom/burstly/lib/service/ServerConfigurationService$IServerConfigurable;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache$1;,
        Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache$SDCardListener;
    }
.end annotation

.annotation system Ldalvik/annotation/Signature;
    value = {
        "Ljava/lang/Object;",
        "Lcom/burstly/lib/cache/ICache",
        "<",
        "Landroid/graphics/Bitmap;",
        ">;",
        "Lcom/burstly/lib/service/ServerConfigurationService$IServerConfigurable;"
    }
.end annotation


# static fields
.field private static final BURSTLY_IMAGE_CACHE_DIR_NAME:Ljava/lang/String; = "burstlyImageCache"

.field private static final CACHE:Ljava/util/HashMap; = null
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/HashMap",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/ref/SoftReference",
            "<",
            "Landroid/graphics/Bitmap;",
            ">;>;"
        }
    .end annotation
.end field

.field private static final CACHE_TIME:Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer; = null

.field private static final IMAGE_CACHE_TTL:Ljava/lang/String; = "imgcachettl"

.field static final LOCK:Ljava/lang/Object; = null

.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final TAG:Ljava/lang/String; = "ImageCache"

.field private static final TIME_TO_LIVE:J = 0x7b98a000L

.field static sCacheDir:Ljava/io/File;

.field private static sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

.field private static volatile sUseMemoryCache:Z


# direct methods
.method static constructor <clinit>()V
    .locals 3

    .prologue
    .line 69
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 84
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE:Ljava/util/HashMap;

    .line 89
    new-instance v0, Ljava/lang/Object;

    invoke-direct {v0}, Ljava/lang/Object;-><init>()V

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOCK:Ljava/lang/Object;

    .line 99
    const/4 v0, 0x1

    sput-boolean v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sUseMemoryCache:Z

    .line 109
    new-instance v0, Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;

    const-wide/32 v1, 0x7b98a000

    invoke-static {v1, v2}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-direct {v0, v1}, Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;-><init>(Ljava/lang/Long;)V

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE_TIME:Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;

    return-void
.end method

.method private constructor <init>(Landroid/content/Context;)V
    .locals 4
    .parameter "context"

    .prologue
    .line 116
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 117
    invoke-static {p0}, Lcom/burstly/lib/service/ServerConfigurationService;->addRecipient(Lcom/burstly/lib/service/ServerConfigurationService$IServerConfigurable;)V

    .line 118
    invoke-static {}, Lcom/burstly/lib/util/Utils;->canWriteToSDCard()Z

    move-result v1

    .line 119
    .local v1, testedResult:Z
    invoke-virtual {p1}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;

    move-result-object v0

    .line 120
    .local v0, applicationContext:Landroid/content/Context;
    invoke-static {v1, v0}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->initCacheDir(ZLandroid/content/Context;)V

    .line 122
    new-instance v2, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache$SDCardListener;

    const/4 v3, 0x0

    invoke-direct {v2, v0, v3}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache$SDCardListener;-><init>(Landroid/content/Context;Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache$1;)V

    invoke-static {v2}, Lcom/burstly/lib/service/SdCardWatchingService;->addNotificationListener(Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;)V

    .line 123
    invoke-static {p0}, Lcom/burstly/lib/cache/CacheManager;->registerCache(Lcom/burstly/lib/cache/ICache;)V

    .line 124
    return-void
.end method

.method private static createCacheDirectoryIfNeed()V
    .locals 6

    .prologue
    .line 176
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    invoke-virtual {v0}, Ljava/io/File;->exists()Z

    move-result v0

    if-nez v0, :cond_0

    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    invoke-virtual {v0}, Ljava/io/File;->mkdirs()Z

    move-result v0

    if-nez v0, :cond_0

    .line 177
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v1, "ImageCache"

    const-string v2, "Could not create cache directory : {0} !"

    const/4 v3, 0x1

    new-array v3, v3, [Ljava/lang/Object;

    const/4 v4, 0x0

    sget-object v5, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    aput-object v5, v3, v4

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 179
    :cond_0
    return-void
.end method

.method private static createDecodeParameters()Landroid/graphics/BitmapFactory$Options;
    .locals 2

    .prologue
    .line 289
    new-instance v0, Landroid/graphics/BitmapFactory$Options;

    invoke-direct {v0}, Landroid/graphics/BitmapFactory$Options;-><init>()V

    .line 290
    .local v0, bfOptions:Landroid/graphics/BitmapFactory$Options;
    const/4 v1, 0x0

    iput-boolean v1, v0, Landroid/graphics/BitmapFactory$Options;->inDither:Z

    .line 293
    const v1, 0x8000

    new-array v1, v1, [B

    iput-object v1, v0, Landroid/graphics/BitmapFactory$Options;->inTempStorage:[B

    .line 294
    return-object v0
.end method

.method private deleteCachedFiles([Ljava/io/File;)V
    .locals 10
    .parameter "files"

    .prologue
    .line 335
    move-object v0, p1

    .local v0, arr$:[Ljava/io/File;
    array-length v3, v0

    .local v3, len$:I
    const/4 v2, 0x0

    .local v2, i$:I
    :goto_0
    if-ge v2, v3, :cond_1

    aget-object v1, v0, v2

    .line 336
    .local v1, file:Ljava/io/File;
    invoke-virtual {v1}, Ljava/io/File;->delete()Z

    move-result v4

    if-nez v4, :cond_0

    .line 337
    sget-object v4, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v5, "ImageCache"

    const-string v6, "Could not delete cached image file: {0} !"

    const/4 v7, 0x1

    new-array v7, v7, [Ljava/lang/Object;

    const/4 v8, 0x0

    invoke-virtual {v1}, Ljava/io/File;->getAbsoluteFile()Ljava/io/File;

    move-result-object v9

    aput-object v9, v7, v8

    invoke-virtual {v4, v5, v6, v7}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 335
    :cond_0
    add-int/lit8 v2, v2, 0x1

    goto :goto_0

    .line 341
    .end local v1           #file:Ljava/io/File;
    :cond_1
    return-void
.end method

.method private getBitmap(Ljava/lang/String;)Landroid/graphics/Bitmap;
    .locals 18
    .parameter "url"

    .prologue
    .line 199
    sget-object v9, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOCK:Ljava/lang/Object;

    monitor-enter v9

    .line 200
    :try_start_0
    invoke-virtual/range {p1 .. p1}, Ljava/lang/String;->hashCode()I

    move-result v8

    invoke-static {v8}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v3

    .line 201
    .local v3, filename:Ljava/lang/String;
    invoke-static {}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->createCacheDirectoryIfNeed()V

    .line 202
    new-instance v2, Ljava/io/File;

    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    invoke-direct {v2, v8, v3}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    .line 204
    .local v2, file:Ljava/io/File;
    invoke-static {v2}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->readFromFile(Ljava/io/File;)Landroid/graphics/Bitmap;

    move-result-object v4

    .line 205
    .local v4, image:Landroid/graphics/Bitmap;
    if-eqz v4, :cond_0

    .line 206
    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v10, "ImageCache"

    const-string v11, "Image {0} loaded from file cache."

    const/4 v12, 0x1

    new-array v12, v12, [Ljava/lang/Object;

    const/4 v13, 0x0

    aput-object p1, v12, v13

    invoke-virtual {v8, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 207
    monitor-exit v9
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 233
    .end local v4           #image:Landroid/graphics/Bitmap;
    :goto_0
    return-object v4

    .line 211
    .restart local v4       #image:Landroid/graphics/Bitmap;
    :cond_0
    :try_start_1
    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v10, "ImageCache"

    const-string v11, "Image {0} is loading from internet."

    const/4 v12, 0x1

    new-array v12, v12, [Ljava/lang/Object;

    const/4 v13, 0x0

    aput-object p1, v12, v13

    invoke-virtual {v8, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 212
    invoke-static/range {p1 .. p1}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->openStream(Ljava/lang/String;)Ljava/io/InputStream;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0
    .catch Ljava/net/SocketTimeoutException; {:try_start_1 .. :try_end_1} :catch_0
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_2

    move-result-object v5

    .line 213
    .local v5, is:Ljava/io/InputStream;
    if-nez v5, :cond_1

    .line 214
    const/4 v4, 0x0

    .end local v4           #image:Landroid/graphics/Bitmap;
    :try_start_2
    monitor-exit v9

    goto :goto_0

    .line 234
    .end local v2           #file:Ljava/io/File;
    .end local v3           #filename:Ljava/lang/String;
    .end local v5           #is:Ljava/io/InputStream;
    :catchall_0
    move-exception v8

    monitor-exit v9
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    throw v8

    .line 216
    .restart local v2       #file:Ljava/io/File;
    .restart local v3       #filename:Ljava/lang/String;
    .restart local v4       #image:Landroid/graphics/Bitmap;
    .restart local v5       #is:Ljava/io/InputStream;
    :cond_1
    :try_start_3
    new-instance v6, Ljava/io/FileOutputStream;

    invoke-direct {v6, v2}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V

    .line 217
    .local v6, os:Ljava/io/OutputStream;
    invoke-static {v5, v6}, Lcom/burstly/lib/util/Utils;->writeToOutput(Ljava/io/InputStream;Ljava/io/OutputStream;)V

    .line 218
    invoke-virtual {v5}, Ljava/io/InputStream;->close()V

    .line 219
    invoke-virtual {v6}, Ljava/io/OutputStream;->close()V

    .line 220
    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v10, "ImageCache"

    const-string v11, "{0}KB loaded."

    const/4 v12, 0x1

    new-array v12, v12, [Ljava/lang/Object;

    const/4 v13, 0x0

    invoke-virtual {v2}, Ljava/io/File;->length()J

    move-result-wide v14

    const-wide/16 v16, 0x400

    div-long v14, v14, v16

    invoke-static {v14, v15}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v14

    aput-object v14, v12, v13

    invoke-virtual {v8, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 221
    invoke-static {v2}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->readFromFile(Ljava/io/File;)Landroid/graphics/Bitmap;
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0
    .catch Ljava/net/SocketTimeoutException; {:try_start_3 .. :try_end_3} :catch_0
    .catch Ljava/io/IOException; {:try_start_3 .. :try_end_3} :catch_1
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_2

    move-result-object v4

    .end local v4           #image:Landroid/graphics/Bitmap;
    :try_start_4
    monitor-exit v9

    goto :goto_0

    .line 223
    .end local v5           #is:Ljava/io/InputStream;
    .end local v6           #os:Ljava/io/OutputStream;
    .restart local v4       #image:Landroid/graphics/Bitmap;
    :catch_0
    move-exception v7

    .line 224
    .local v7, ste:Ljava/net/SocketTimeoutException;
    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v10, "ImageCache"

    const-string v11, "Could not read image data in specified {0} timeout!"

    const/4 v12, 0x1

    new-array v12, v12, [Ljava/lang/Object;

    const/4 v13, 0x0

    invoke-static {}, Lcom/burstly/lib/network/TimeoutManager;->getConnectTimeout()I

    move-result v14

    invoke-static {v14}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v14

    aput-object v14, v12, v13

    invoke-virtual {v8, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 233
    .end local v7           #ste:Ljava/net/SocketTimeoutException;
    :goto_1
    const/4 v4, 0x0

    monitor-exit v9

    goto :goto_0

    .line 227
    :catch_1
    move-exception v0

    .line 228
    .local v0, e:Ljava/io/IOException;
    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v10, "ImageCache"

    const-string v11, "Could not open stream to read image! Check your connection."

    const/4 v12, 0x0

    new-array v12, v12, [Ljava/lang/Object;

    invoke-virtual {v8, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1

    .line 230
    .end local v0           #e:Ljava/io/IOException;
    :catch_2
    move-exception v1

    .line 231
    .local v1, ex:Ljava/lang/Exception;
    sget-object v8, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v10, "ImageCache"

    invoke-virtual {v1}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v11

    const/4 v12, 0x0

    new-array v12, v12, [Ljava/lang/Object;

    invoke-virtual {v8, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0

    goto :goto_1
.end method

.method public static getCache()Ljava/util/Map;
    .locals 1
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/ref/SoftReference",
            "<",
            "Landroid/graphics/Bitmap;",
            ">;>;"
        }
    .end annotation

    .prologue
    .line 427
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE:Ljava/util/HashMap;

    return-object v0
.end method

.method public static getInstance()Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;
    .locals 4

    .prologue
    .line 360
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    if-nez v0, :cond_0

    .line 361
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v1, "ImageCache"

    const-string v2, "Image cache is not initialized! Call ImageCache.initCache first!"

    const/4 v3, 0x0

    new-array v3, v3, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 363
    :cond_0
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    return-object v0
.end method

.method public static getInstance(Landroid/content/Context;)Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;
    .locals 4
    .parameter "currentContext"

    .prologue
    .line 373
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    if-nez v0, :cond_0

    .line 374
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v1, "ImageCache"

    const-string v2, "Image cache is not initialized. Initializing..."

    const/4 v3, 0x0

    new-array v3, v3, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 375
    invoke-static {p0}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->initCache(Landroid/content/Context;)V

    .line 377
    :cond_0
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    return-object v0
.end method

.method static declared-synchronized initCache(Landroid/content/Context;)V
    .locals 2
    .parameter "ctxt"

    .prologue
    .line 349
    const-class v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    monitor-enter v1

    :try_start_0
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    if-nez v0, :cond_0

    .line 350
    new-instance v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    invoke-direct {v0, p0}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;-><init>(Landroid/content/Context;)V

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 352
    :cond_0
    monitor-exit v1

    return-void

    .line 349
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method static initCacheDir(ZLandroid/content/Context;)V
    .locals 6
    .parameter "isUsable"
    .parameter "context"

    .prologue
    .line 160
    if-eqz p1, :cond_0

    .line 162
    if-eqz p0, :cond_1

    .line 163
    new-instance v0, Ljava/io/File;

    invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;

    move-result-object v1

    const-string v2, "burstlyImageCache"

    invoke-direct {v0, v1, v2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    .line 167
    :goto_0
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v1, "ImageCache"

    const-string v2, "Image cache directory is : {0}"

    const/4 v3, 0x1

    new-array v3, v3, [Ljava/lang/Object;

    const/4 v4, 0x0

    sget-object v5, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    aput-object v5, v3, v4

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 168
    invoke-static {}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->createCacheDirectoryIfNeed()V

    .line 170
    :cond_0
    return-void

    .line 165
    :cond_1
    new-instance v0, Ljava/io/File;

    invoke-virtual {p1}, Landroid/content/Context;->getCacheDir()Ljava/io/File;

    move-result-object v1

    const-string v2, "burstlyImageCache"

    invoke-direct {v0, v1, v2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    goto :goto_0
.end method

.method static isUseMemoryCache()Z
    .locals 1

    .prologue
    .line 409
    sget-boolean v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sUseMemoryCache:Z

    return v0
.end method

.method private static openStream(Ljava/lang/String;)Ljava/io/InputStream;
    .locals 10
    .parameter "url"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    const/4 v3, 0x0

    const/4 v8, 0x0

    .line 245
    invoke-static {p0}, Lcom/burstly/lib/util/Utils;->makeGetRequest(Ljava/lang/String;)Lorg/apache/http/HttpResponse;

    move-result-object v1

    .line 246
    .local v1, response:Lorg/apache/http/HttpResponse;
    invoke-interface {v1}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v4

    invoke-interface {v4}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v2

    .line 247
    .local v2, statusCode:I
    invoke-interface {v1}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v0

    .line 248
    .local v0, entity:Lorg/apache/http/HttpEntity;
    const/16 v4, 0xc8

    if-eq v2, v4, :cond_0

    .line 249
    sget-object v4, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v5, "ImageCache"

    const-string v6, "Can not download image {1}, response code is {2}"

    const/4 v7, 0x2

    new-array v7, v7, [Ljava/lang/Object;

    aput-object p0, v7, v8

    const/4 v8, 0x1

    invoke-static {v2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v9

    aput-object v9, v7, v8

    invoke-virtual {v4, v5, v6, v7}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 255
    :goto_0
    return-object v3

    .line 251
    :cond_0
    invoke-interface {v0}, Lorg/apache/http/HttpEntity;->getContentLength()J

    move-result-wide v4

    const-wide/16 v6, 0x0

    cmp-long v4, v4, v6

    if-nez v4, :cond_1

    .line 252
    sget-object v4, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v5, "ImageCache"

    const-string v6, "Image size is 0 - will not serve the image."

    new-array v7, v8, [Ljava/lang/Object;

    invoke-virtual {v4, v5, v6, v7}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_0

    .line 255
    :cond_1
    invoke-interface {v0}, Lorg/apache/http/HttpEntity;->getContent()Ljava/io/InputStream;

    move-result-object v3

    goto :goto_0
.end method

.method private static readFromFile(Ljava/io/File;)Landroid/graphics/Bitmap;
    .locals 14
    .parameter "file"

    .prologue
    .line 266
    :try_start_0
    invoke-virtual {p0}, Ljava/io/File;->lastModified()J

    move-result-wide v0

    .line 267
    .local v0, creationDate:J
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v5

    sget-object v7, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE_TIME:Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;

    invoke-virtual {v7}, Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;->get()J

    move-result-wide v7

    add-long/2addr v7, v0

    cmp-long v5, v5, v7

    if-gez v5, :cond_0

    .line 268
    invoke-static {}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->createDecodeParameters()Landroid/graphics/BitmapFactory$Options;

    move-result-object v4

    .line 269
    .local v4, options:Landroid/graphics/BitmapFactory$Options;
    new-instance v5, Ljava/io/FileInputStream;

    invoke-direct {v5, p0}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V

    const/4 v6, 0x0

    invoke-static {v5, v6, v4}, Landroid/graphics/BitmapFactory;->decodeStream(Ljava/io/InputStream;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;

    move-result-object v2

    .line 270
    .local v2, decodeStream:Landroid/graphics/Bitmap;
    sget-object v5, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "ImageCache"

    const-string v7, "Loaded image size: {0}KB."

    const/4 v8, 0x1

    new-array v8, v8, [Ljava/lang/Object;

    const/4 v9, 0x0

    invoke-virtual {p0}, Ljava/io/File;->length()J

    move-result-wide v10

    const-wide/16 v12, 0x400

    div-long/2addr v10, v12

    invoke-static {v10, v11}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v10

    aput-object v10, v8, v9

    invoke-virtual {v5, v6, v7, v8}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 280
    .end local v0           #creationDate:J
    .end local v2           #decodeStream:Landroid/graphics/Bitmap;
    .end local v4           #options:Landroid/graphics/BitmapFactory$Options;
    :goto_0
    return-object v2

    .line 273
    .restart local v0       #creationDate:J
    :cond_0
    const-wide/16 v5, 0x0

    cmp-long v5, v0, v5

    if-eqz v5, :cond_1

    invoke-virtual {p0}, Ljava/io/File;->delete()Z

    move-result v5

    if-nez v5, :cond_1

    .line 274
    sget-object v5, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "ImageCache"

    const-string v7, "Could not delete file  \'\'{0}\'\'. Temp directory is {1}"

    const/4 v8, 0x2

    new-array v8, v8, [Ljava/lang/Object;

    const/4 v9, 0x0

    aput-object p0, v8, v9

    const/4 v9, 0x1

    sget-object v10, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    aput-object v10, v8, v9

    invoke-virtual {v5, v6, v7, v8}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    .line 280
    .end local v0           #creationDate:J
    :cond_1
    :goto_1
    const/4 v2, 0x0

    goto :goto_0

    .line 277
    :catch_0
    move-exception v3

    .line 278
    .local v3, e:Ljava/io/FileNotFoundException;
    sget-object v5, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "ImageCache"

    const-string v7, "No cached image file with {0} name."

    const/4 v8, 0x1

    new-array v8, v8, [Ljava/lang/Object;

    const/4 v9, 0x0

    aput-object p0, v8, v9

    invoke-virtual {v5, v6, v7, v8}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1
.end method

.method static setUseMemoryCache(Z)V
    .locals 0
    .parameter "useMemoryCache"

    .prologue
    .line 418
    sput-boolean p0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sUseMemoryCache:Z

    .line 419
    return-void
.end method


# virtual methods
.method public clearCache(Z)V
    .locals 8
    .parameter "cleanTempDir"

    .prologue
    .line 303
    sget-object v2, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOCK:Ljava/lang/Object;

    monitor-enter v2

    .line 304
    :try_start_0
    invoke-static {}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->isUseMemoryCache()Z

    move-result v1

    if-eqz v1, :cond_0

    .line 306
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "ImageCache"

    const-string v4, "Cleaning images memory cache..."

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 307
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE:Ljava/util/HashMap;

    invoke-virtual {v1}, Ljava/util/HashMap;->clear()V

    .line 308
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "ImageCache"

    const-string v4, "Cleared."

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 310
    :cond_0
    if-eqz p1, :cond_2

    .line 312
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "ImageCache"

    const-string v4, "Cleaning images files cache..."

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 313
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    invoke-virtual {v1}, Ljava/io/File;->listFiles()[Ljava/io/File;

    move-result-object v0

    .line 314
    .local v0, files:[Ljava/io/File;
    if-eqz v0, :cond_1

    array-length v1, v0

    if-nez v1, :cond_3

    .line 315
    :cond_1
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "ImageCache"

    const-string v4, "No cached image files."

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 326
    .end local v0           #files:[Ljava/io/File;
    :cond_2
    :goto_0
    monitor-exit v2

    .line 327
    return-void

    .line 317
    .restart local v0       #files:[Ljava/io/File;
    :cond_3
    invoke-direct {p0, v0}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->deleteCachedFiles([Ljava/io/File;)V

    .line 318
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    invoke-virtual {v1}, Ljava/io/File;->delete()Z

    move-result v1

    if-nez v1, :cond_4

    .line 319
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "ImageCache"

    const-string v4, "Could not delete cache directory: {0} because of some cached files could not be deleted."

    const/4 v5, 0x1

    new-array v5, v5, [Ljava/lang/Object;

    const/4 v6, 0x0

    sget-object v7, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    aput-object v7, v5, v6

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 323
    :cond_4
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v3, "ImageCache"

    const-string v4, "Cleared {0} image files."

    const/4 v5, 0x1

    new-array v5, v5, [Ljava/lang/Object;

    const/4 v6, 0x0

    array-length v7, v0

    invoke-static {v7}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v7

    aput-object v7, v5, v6

    invoke-virtual {v1, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_0

    .line 326
    .end local v0           #files:[Ljava/io/File;
    :catchall_0
    move-exception v1

    monitor-exit v2
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v1
.end method

.method public configure(Ljava/util/Map;)V
    .locals 6
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Object;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 437
    .local p1, configurationData:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;"
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "ImageCache"

    const-string v3, "Confuiring ImageCache with params: {0}"

    const/4 v4, 0x1

    new-array v4, v4, [Ljava/lang/Object;

    const/4 v5, 0x0

    aput-object p1, v4, v5

    invoke-virtual {v1, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 438
    const-string v1, "imgcachettl"

    invoke-interface {p1, v1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 439
    .local v0, newTtl:Ljava/lang/String;
    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE_TIME:Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;

    invoke-virtual {v1, v0}, Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;->setNewTTLValue(Ljava/lang/String;)V

    .line 440
    return-void
.end method

.method public getCacheDir()Ljava/io/File;
    .locals 1

    .prologue
    .line 188
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    return-object v0
.end method

.method public getResource(Ljava/lang/String;)Landroid/graphics/Bitmap;
    .locals 8
    .parameter "resourceId"

    .prologue
    .line 382
    const/4 v0, 0x0

    .line 383
    .local v0, image:Landroid/graphics/Bitmap;
    invoke-static {}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->isUseMemoryCache()Z

    move-result v2

    if-eqz v2, :cond_2

    .line 384
    sget-object v3, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOCK:Ljava/lang/Object;

    monitor-enter v3

    .line 385
    :try_start_0
    sget-object v2, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE:Ljava/util/HashMap;

    invoke-virtual {v2, p1}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v2

    if-eqz v2, :cond_0

    sget-object v2, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE:Ljava/util/HashMap;

    invoke-virtual {v2, p1}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/ref/SoftReference;

    invoke-virtual {v2}, Ljava/lang/ref/SoftReference;->get()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Landroid/graphics/Bitmap;

    move-object v0, v2

    .line 386
    :goto_0
    if-eqz v0, :cond_1

    .line 387
    sget-object v2, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v4, "ImageCache"

    const-string v5, "Image {0} loaded from memory cache."

    const/4 v6, 0x1

    new-array v6, v6, [Ljava/lang/Object;

    const/4 v7, 0x0

    aput-object p1, v6, v7

    invoke-virtual {v2, v4, v5, v6}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 388
    monitor-exit v3

    move-object v1, v0

    .line 398
    .end local v0           #image:Landroid/graphics/Bitmap;
    .local v1, image:Landroid/graphics/Bitmap;
    :goto_1
    return-object v1

    .line 385
    .end local v1           #image:Landroid/graphics/Bitmap;
    .restart local v0       #image:Landroid/graphics/Bitmap;
    :cond_0
    const/4 v0, 0x0

    goto :goto_0

    .line 390
    :cond_1
    monitor-exit v3
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 392
    :cond_2
    invoke-direct {p0, p1}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->getBitmap(Ljava/lang/String;)Landroid/graphics/Bitmap;

    move-result-object v0

    .line 393
    invoke-static {}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->isUseMemoryCache()Z

    move-result v2

    if-eqz v2, :cond_3

    if-eqz v0, :cond_3

    .line 394
    sget-object v3, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->LOCK:Ljava/lang/Object;

    monitor-enter v3

    .line 395
    :try_start_1
    sget-object v2, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE:Ljava/util/HashMap;

    new-instance v4, Ljava/lang/ref/SoftReference;

    invoke-direct {v4, v0}, Ljava/lang/ref/SoftReference;-><init>(Ljava/lang/Object;)V

    invoke-virtual {v2, p1, v4}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 396
    monitor-exit v3
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1

    :cond_3
    move-object v1, v0

    .line 398
    .end local v0           #image:Landroid/graphics/Bitmap;
    .restart local v1       #image:Landroid/graphics/Bitmap;
    goto :goto_1

    .line 390
    .end local v1           #image:Landroid/graphics/Bitmap;
    .restart local v0       #image:Landroid/graphics/Bitmap;
    :catchall_0
    move-exception v2

    :try_start_2
    monitor-exit v3
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    throw v2

    .line 396
    :catchall_1
    move-exception v2

    :try_start_3
    monitor-exit v3
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_1

    throw v2
.end method

.method public bridge synthetic getResource(Ljava/lang/String;)Ljava/lang/Object;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    invoke-virtual {p0, p1}, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->getResource(Ljava/lang/String;)Landroid/graphics/Bitmap;

    move-result-object v0

    return-object v0
.end method

.method public getTtl()J
    .locals 2

    .prologue
    .line 444
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->CACHE_TIME:Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;

    invoke-virtual {v0}, Lcom/burstly/lib/component/networkcomponent/burstly/DayBasedCacheTimer;->get()J

    move-result-wide v0

    return-wide v0
.end method

.method public isConstantRecepient()Z
    .locals 1

    .prologue
    .line 432
    const/4 v0, 0x1

    return v0
.end method

.method public release()V
    .locals 1

    .prologue
    const/4 v0, 0x0

    .line 449
    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sInstance:Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;

    .line 450
    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/ImageCache;->sCacheDir:Ljava/io/File;

    .line 451
    return-void
.end method
